<?php

if (PHP_VERSION < 7) {
    exit('Please use php7 or above');
}

require __DIR__ . '/vendor/autoload.php';

//公共方法
require __DIR__ . '/application/common.php';

$Obj = new \zqphp\AutoLoad(__DIR__ . '/application');

$Obj->SetStop([
//    'index/main' => 'GET,POST'
    'index/thinkOrm' => 'POST'
]);

$Obj->SetAlias('thinkOrm', 'index/thinkOrm', 'GET');

$Obj->Access('index/test/main', function () {
    echo "当通过GET或者POST可以访问到此路由";
}, 'GET,POST');

//设置错误接收
$Obj->SetError(function ($data,$error){
    dump('==============处理后的错误内容==============');
    dump($data);
    dump('==============处理前的错误内容==============');
    dump($error);
});

//设置Worker
$Obj->SetWorker(['count'=>4,'name'=>'shiroi']);

//单个设置
$Obj->SetWorker('onWorkerStart',function($worker){

    echo "Worker starting...\n";

    //内存监控(五分钟监控一次)
    $start_memory = memory_get_usage();
    \Workerman\Lib\Timer::add(300,function () use ($start_memory) {
        $end_memory = memory_get_usage();
        $use_memory = $end_memory - $start_memory;
        $use_memory = $use_memory/1024/1024;
        echo "当前脚本消耗内存大小为：{$use_memory}MB\n";
    },[]);

    //处理MySQL server has gone away问题
    \Workerman\Lib\Timer::add(30,function () {
        \think\facade\Db::setConfig(config('Mysql'));
        echo (new \MathieuViossat\Util\ArrayToTextTable(
            \think\facade\Db::query("SHOW PROCESSLIST;")
        ))->getTable();
    });
});

$Obj->Run('8888');